package com.jt.chapter06.config.exception;

import com.jt.chapter06.common.Result;
import com.jt.chapter06.common.exception.ValidateCodeException;
import com.jt.chapter06.common.exception.BizServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author jiang tao
 * @date 2022/1/21
 * @description:
 **/
@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalException {

    @ExceptionHandler(value = {BizServiceException.class})
    public Result notFoundException(BizServiceException ex) {
        log.info("BizServiceException:{}.", ex.getMessage());
        return Result.fail("302",ex.getMessage());
    }

    @ExceptionHandler(value = ValidateCodeException.class)
    public Result validateCodeException(ValidateCodeException e){
        log.info("ValidateCodeException:{}.", e.getMessage());
        return Result.fail("302",e.getMessage());
    }


}
